﻿function FrameWork() {
    window.AutoCollapsed = false;
    var MenuStart, MenuSecond = "", MenuThird = "";

    $("#MenuStart").bind("click", function () {
        $("#StartMenu").slideDown("fast");
    });
    $("#MenuClose").bind("click", function () {
        $("#StartMenu").slideUp("fast");
    });
    $("#StartMenu a").bind("click", function () {
        if (this.id == "Exit") {
            $("#StartMenu").slideUp("fast");
            location.href = "/Frame/Login/";
        } else {
            MenuStart = $(this).find("span").html();
            MenuSecond = "";
            MenuThird = "";
            SetLocation();
            ActMenuGap("Open");
            $("#StartMenu").slideUp("fast");
            $("#MenuSecondPanel .MenuSecondPanel").slideUp("fast");
            $("#MainFrame").css("visibility", "hidden");
            $("#MainFrame").attr("src", "");
            $("#MenuSecondPanel .MenuThird").css("display", "none");
            $("#MenuSecondPanel .MenuSecondPanel [class='MenuSecond SecondCurrent']").attr("class", "MenuSecond SecondNormal");
            $("#MenuSecondPanel .MenuThirdList [class='ThirdCurrent']").attr("class", "ThirdNormal");
            $("#Main").removeAttr("style");
            $("#" + this.id.replace(/MenuFirst_/, "MenuSecond_")).slideDown("fast");
            $("#" + this.id.replace(/MenuFirst_/, "MenuSecond_") + " .MenuThird:first").slideDown("fast");
        }
    });
    $("#MenuSecondPanel .MenuSecondPanel .MenuSecond").bind("click", function () {
        $("#MenuSecondPanel .MenuThird").slideUp("fast");
        $("#" + this.id.replace(/MenuSecond_/, "MenuThird_")).slideDown("fast");
        this.blur();
    });
    $("#MenuSecondPanel .MenuSecondPanel .MenuThirdList a").bind("click", function () {
        MenuSecond = $("#" + $(this).parent().parent().attr("id").replace(/MenuThird_/, "MenuSecond_")).html();
        MenuThird = $(this).html();
        SetLocation();
        $("#MainFrame").css("visibility", "visible");
        $("#MenuSecondPanel .MenuThirdList [class='ThirdCurrent']").attr("class", "ThirdNormal");
        $(this).attr("class", "ThirdCurrent");
        $("#MenuSecondPanel .MenuSecondPanel [class='MenuSecond SecondCurrent']").attr("class", "MenuSecond SecondNormal");
        $("#" + $(this).parent().parent().attr("id").replace(/MenuThird_/, "MenuSecond_")).attr("class", "MenuSecond SecondCurrent");
        this.blur();
        if (window.AutoCollapsed) {
            ActMenuGap("Close");
        }
    });

    window.SetMainHeight = function () {
        window.MainHeight = $(window).height() - $("#Top").outerHeight(true);
        $("#MenuGap, #MenuGap a, #MainFrame").css("height", window.MainHeight + "px");
    }

    $(window).resize(function () {
        window.SetMainHeight();   
        if ($("#Top").outerWidth(true) < 1260) {
            window.AutoCollapsed = true;
            ActMenuGap("Close");
        } else {
            window.AutoCollapsed = false;
            ActMenuGap("Open");
        }
    });

    $("#MenuGap").mouseover(function () {
        $("#MenuGap").attr("class", "MenuGapOver");
    });

    $("#MenuGap").mouseout(function () {
        $("#MenuGap").attr("class", "MenuGapOut");
    });

    $("#MenuGap").click(function () {
        ActMenuGap("Auto");
    });

    function SetLocation() {
        var Str = "当前位置：" + MenuStart;
        if (MenuSecond != "" && MenuThird != "") {
            Str += " > " + MenuSecond + " > " + MenuThird;
        }
        $("#MenuStartName").html(Str);
    }

    function ActMenuGap(Type) {
        switch(Type)
        {
            case "Auto":
                AnimateMenuGap($("#MenuSecondPanelDiv").css("width") == "1px");
                break;
            default:
                AnimateMenuGap(Type == "Open");
                break;
        }
    }

    function AnimateMenuGap(OpenClose) {
        if (OpenClose) {
            $("#MenuSecondPanel").css("display", "");
            $("#MenuSecondPanel").css("width", "1px;");
            $("#MenuSecondPanel, #MenuSecondPanelDiv").animate({ width: "160px" }, "fast", null, function () { $("#MenuGap span").attr("class", "ui-icon ui-icon-triangle-1-w"); });
        } else {
            $("#MenuSecondPanel, #MenuSecondPanelDiv").animate({ width: "1px" }, "fast", null, function () { $("#MenuSecondPanel").css("display", "none"); $("#MenuGap span").attr("class", "ui-icon ui-icon-triangle-1-e") });
        }
    }

    window.SetMainHeight();
}

$(function () {
    var frameWork = new FrameWork();

    if ($("#Top").outerWidth(true) < 1260) {
        window.AutoCollapsed = true;
    } else {
        window.AutoCollapsed = false;
    }              

    setInterval("$.ajax({ url: '/Frame/KeepLogin/', type: 'POST', timeout: 60000, data: {}, dataType: 'json' });", 10 * 60 * 1000);
});